//
//  AddCarDriverVC.m
//  阿帕
//
//  Created by mac on 2020/9/14.
//  Copyright © 2020 GCY. All rights reserved.
//

#import "AddCarDriverVC.h"
#import "ImageUploadViewController.h"
#import "STPickerSingle.h"
#import "CYCityChooseView.h"
#import "TZImagePickerController.h"

@interface AddCarDriverVC ()<DeliveredImageUrlDelegate, STPickerSingleDelegate, CYChooseRegionDelegate, TZImagePickerControllerDelegate>
{
    NSString *_workLicenseDueDate;
    NSString *_driverLicenseDueDate;//驾驶证到期日期
    NSString *_jiaShiZhengUrl;
    NSString *_workLicenseImg;
    NSString *_idCardFrontUrl;
    NSString *_idCardReverseUrl;
    NSString *_driverImg;
    NSString *_safeDutyInsureImg;//安全责任险照片
    NSString *_stateImg;
    //    NSString *_vehicleLicenseImg;//行驶证
    
    NSString *_vehicleClass;//准驾车型
    NSString *_driverLicenseFromDate;//驾驶证有效期开始
    
    NSString *_provinceCode;
    NSString *_cityCode;
    NSString *_countyCode;
    
    NSString *_sex;//性别
    NSString *_diverTypeStr;//独立司机/车队司机
    NSString *_lastIdardDueDate;//记录上一次选择身份证到期的日期
    NSString *_lastDriverLicenseDueDate;//记录上一次选择驾驶证到期的日期

    NSInteger _isTax;///天津税务开关
    
    BOOL _idCardIsLongtime;//身份证是否是长期
    BOOL _licenseIsLongtime;//驾驶证是否是长期
    
    BOOL _isLinked;
    NSInteger _reportPlatform;//性别、车轴开关

}
@property (strong , nonatomic)NSDictionary *dynamicFieldDic;

@property (strong , nonatomic)UIButton *saveBtn;
@property (strong , nonatomic)UIButton *driverLicenseBtn;
@property (strong , nonatomic)UIButton *identificationBtn;
@property (strong , nonatomic)UIButton *identificationBackBtn;
@property (strong , nonatomic)UIButton *workLicenseBtn;
@property (strong , nonatomic)UIButton *driverImgBtn;
@property (strong , nonatomic)UIButton *safeDutyInsureImgBtn;
@property (strong , nonatomic)UIButton *stateImgBtn;

@property (strong , nonatomic)UITextField *nameTF;

@property (strong , nonatomic)UITextField *idCardTF;

@property (strong , nonatomic)UITextField *lianXiFangShiTF;

@property (strong , nonatomic)UITextField *daoLuYunShuCongYeNumTF;

@property (strong , nonatomic)UITextField *passwordTF;

@property (strong , nonatomic)UITextField *passwordConfTF;

@property (strong , nonatomic)UITextField *detailAddressTF;

@property (strong , nonatomic)UITextField *workUnitTF;

@property (strong , nonatomic)UITextField *vehicleJiaShiZhengTF;

@property (strong , nonatomic)UITextField *tongXunDiZhiTF;

@property (strong , nonatomic)UITextField *jiaShiZhengFaZhengJiGuanTF;

@property (strong , nonatomic)UITextField *zhunJiavehicleTypeTF;

@property (strong , nonatomic)UITextField *workLicenseDueDateTF;

@property (strong , nonatomic)UITextField *driverLicenseFromDateTF;

@property (strong , nonatomic)UITextField *driverLicenseDueDateTF;

@property (strong , nonatomic)UITextField *idCardDueDateTF;
@property (strong , nonatomic)UITextField *vehicleActualOwnerTF;
@property (strong , nonatomic)UITextField *vehicleActualOwnerPhoneTF;
@property (strong , nonatomic)UITextField *vehicleBrandTF;

@property (strong , nonatomic)UILabel *idCardDueDateRemindLabel;///身份证到期提醒文字

///必填星号
@property (strong , nonatomic)UILabel *driverLicenseImgView;
@property (strong , nonatomic)UILabel *identificationImgView;
@property (strong , nonatomic)UILabel *identificationBackImgView;
@property (strong , nonatomic)UILabel *safeDutyInsureImgView;
@property (strong , nonatomic)UILabel *driverImgView;
@property (strong , nonatomic)UILabel *workLicenseImgView;
@property (strong , nonatomic)UILabel *nameTFView;
@property (strong , nonatomic)UILabel *idCardTFView;
@property (strong , nonatomic)UILabel *idCardDueDateView;
@property (strong , nonatomic)UILabel *lianXiFangShiAsterisk;
@property (strong , nonatomic)UILabel *daoLuYunShuCongYeNumTFView;
@property (strong , nonatomic)UILabel *detailAddressTFView;
@property (strong , nonatomic)UILabel *workUnitTFView;
@property (strong , nonatomic)UILabel *vehicleJiaShiZhengTFView;
@property (strong , nonatomic)UILabel *tongXunDiZhiTFView;
@property (strong , nonatomic)UILabel *jiaShiZhengFaZhengJiGuanTFView;
@property (strong , nonatomic)UILabel *zhunJiavehicleTypeTFView;
@property (strong , nonatomic)UILabel *workLicenseDueDateTFView;
@property (strong , nonatomic)UILabel *driverLicenseFromDateTFView;
@property (strong , nonatomic)UILabel *driverLicenseDueDateTFView;

@property (strong , nonatomic)UILabel *stateImgAsterisk;
@property (strong , nonatomic)UILabel *affiliatAsterisk;
@property (strong , nonatomic)UILabel *vehicleActualOwnerAsterisk;
@property (strong , nonatomic)UILabel *vehicleActualOwnerPhoneAsterisk;
@property (strong , nonatomic)UILabel *vehicleBrandAsterisk; ///车辆品牌必填星号
@property (strong , nonatomic)UILabel *passwordOne;
@property (strong , nonatomic)UILabel *passwordTwo;
@property (strong , nonatomic)UIView *passwordOneView;
@property (strong , nonatomic)UIView *passwordTwoView;

@property (strong , nonatomic)UIImageView *manImageView;
@property (strong , nonatomic)UIImageView *womenImageView;
@property (strong , nonatomic)UIImageView *duliCarImageView;
@property (strong , nonatomic)UIImageView *cheduiCarImageView;
@property (strong , nonatomic)UIImageView *idCardDateIsLongtimeImageView;
@property (strong , nonatomic)UIImageView *driverLicenseDueDateIsLongtimeImageView;
@property (strong , nonatomic)UIImageView *affiliatedImageView;


@property (strong , nonatomic)NSMutableArray *vehicleClassArray;
@property (strong , nonatomic)NSMutableArray *vechicleClassModelArray;
@property (strong , nonatomic)ImageUploadViewController *uploadImgVC;

/** 照片容器View */
@property (strong , nonatomic)UIView *photoBgView;

/// 驾驶证照片
@property (strong , nonatomic)UIView *driverLicenseImgContainerView;
/// 身份证正面照
@property (strong , nonatomic)UIView *identificationImgContainerView;
/// 身份证背面照
@property (strong , nonatomic)UIView *identificationBackImgContainerView;
/// 司机照
@property (strong , nonatomic)UIView *driverImgContainerView;
/// 道路运输从业资格证
@property (strong , nonatomic)UIView *workLicenseImgContainerView;
/// 安全责任险照
@property (strong , nonatomic)UIView *safeDutyInsureImgContainerView;
/// 车主声明照
@property (strong , nonatomic)UIView *stateImgBgView;
/// 挂靠协议照
@property (strong , nonatomic)UIView *depenDealImgView;


/** 输入容器View */

/// 非必填
@property (strong , nonatomic)UIView *noRequiredBgView;
/// 必填
@property (strong , nonatomic)UIView *requiredBgView;

/// 是否挂靠
@property (strong , nonatomic)UIView *affiliatedBgView;
/// 姓名
@property (strong , nonatomic)UIView *nameContainerView;
/// 联系方式
@property (strong , nonatomic)UIView *phoneContainerView;
/// 性别
@property (strong , nonatomic)UIView *sexBgView;
/// 独立司机/车队司机
@property (strong , nonatomic)UIView *carBgView;
/// 身份证
@property (strong , nonatomic)UIView *idCardContainerView;
/// 道路运输从业资格证号
@property (strong , nonatomic)UIView *workLicenseContainerView;
/// 详细地址
@property (strong , nonatomic)UIView *homeAddressContainerView;
/// 工作单位
@property (strong , nonatomic)UIView *workCompanyContainerView;
/// 机动车驾驶证号
@property (strong , nonatomic)UIView *driverLicenseContainerView;
/// 车辆实际所有人
@property (strong , nonatomic)UIView *vehicleActualOwnerView;
/// 车辆实际所有人联系方式
@property (strong , nonatomic)UIView *vehicleActualOwnerPhoneView;
/// 车辆品牌背景
@property (strong , nonatomic)UIView *vehicleBrandBgView;
/// 通讯地址
@property (strong , nonatomic)UIView *areaListContainerView;
/// 身份证有效期
@property (strong , nonatomic)UIView *idCardDueDateContainerView;
/// 道路运输从业资格证到期日期
@property (strong , nonatomic)UIView *workLicenseDueDateContainerView;
/// 驾驶证发证机关
@property (strong , nonatomic)UIView *driverIssuingOrganizationsContainerView;
/// 准驾车型
@property (strong , nonatomic)UIView *vehicleClassContainerView;
/// 驾驶证有效期开始
@property (strong , nonatomic)UIView *driverLicenseFromDateContainerView;
/// 驾驶证到期日期
@property (strong , nonatomic)UIView *driverLicenseDueDateContainerView;
/// 驾驶证注册日期
@property (strong , nonatomic)UIView *registerDateContainerView;

/// 保存View
@property (strong , nonatomic)UIView *viewSave;

@property(strong,nonatomic)UIScrollView *scrollviewMy;
@end

@implementation AddCarDriverVC

- (void)viewDidLoad {
    
    [super viewDidLoad];
    _scrollviewMy.panGestureRecognizer.delaysTouchesBegan = YES;
    [self baseViewSetup];
    
    [self formValidationSetup];
    
    [self fieldCalibrationRequest];
}

- (void)baseViewSetup {
    
    _jiaShiZhengUrl = @"";
    _idCardFrontUrl = @"";
    _idCardReverseUrl = @"";
    _workLicenseImg = @"";
    _driverImg = @"";
    _workLicenseDueDate = @"";
    _driverLicenseDueDate = @"";
    _vehicleClass = @"";
    _driverLicenseFromDate = @"";
    //    _vehicleLicenseImg= @"";
    _provinceCode = @"";
    _cityCode = @"";
    _countyCode = @"";
    _safeDutyInsureImg = @"";
    _sex = @"";
    _diverTypeStr = @"0";
    _stateImg = @"";//车主声明图片
    _lastIdardDueDate = @"";
    _lastDriverLicenseDueDate = @"";
    _duliCarImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _cheduiCarImageView.image = image(@"gcy_img_home_business_nomal");
    _driverLicenseBtn.titleLabel.font = font(13);
    _identificationBtn.titleLabel.font = font(13);
    _identificationBackBtn.titleLabel.font = font(13);
    _workLicenseBtn.titleLabel.font = font(13);
    _driverImgBtn.titleLabel.font = font(13);
    _stateImgBtn.titleLabel.font = font(13);
    _safeDutyInsureImgBtn.titleLabel.font = font(13);
    [_saveBtn setBackgroundColor:Theme_ColorValue];
    
    if (_addType == 1) {
        self.navigationItem.title = @"修改司机信息";
        //编辑 信息 需要先拉数据
        [self getDriverInfoRequest];
    } else {
        self.navigationItem.title = @"新增司机";
    }
    
    
//    _isTax = [[UserDefaultUtil valueForKey:Login_Branch][@"isTax"] integerValue];///天津税务开关
//    if (_isTax == 1) {
//        _stateImgBgView.hidden = NO;//车主声明照
//        _affiliatedBgView.hidden = NO;//是否挂靠
//        _vehicleActualOwnerView.hidden = NO;//车辆实际所有人
//        _vehicleActualOwnerPhoneView.hidden = NO;//车辆实际所有人联系方式
//        _vehicleBrandBgView.hidden = NO;//车辆品牌
//    }
    
    [self vehicleClassListRequest];
    
    _reportPlatform = [[UserDefaultUtil valueForKey:Login_Branch][@"reportPlatform"] integerValue];
    if (_reportPlatform == 3) {
        //江苏省显示性别
        _sexBgView.hidden = NO;
    }
}

#pragma mark - 动态字段配置请求
- (void)fieldCalibrationRequest {
    
    NSDictionary *parmas = @{@"fieldFrom": @"driver", @"token":[UserDefaultUtil valueForKey:USER_TOKEN],};
    
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], UPDATEFIELDREQUIRED) withParameter:parmas withVC:self netName:@"字段是否必填" success:^(id response, NSString *msg) {
        
        if ([DCSpeedy isBlankDictionary:response] == NO) {
            _dynamicFieldDic = response;
        }
        
        //照片部分
        if ([response[@"driverLicenseImg"] integerValue] == 0 || response[@"driverLicenseImg"] == NULL) {
            _driverLicenseImgView.hidden = YES;
            _driverLicenseImgContainerView.hidden = YES;
        }
        if ([response[@"identificationImg"] integerValue] == 0 || response[@"identificationImg"] == NULL) {
            _identificationImgView.hidden = YES;
            _identificationImgContainerView.hidden = YES;
        }
        if ([response[@"identificationBackImg"] integerValue] == 0 || response[@"identificationBackImg"] == NULL) {
            _identificationBackImgView.hidden = YES;
            _identificationBackImgContainerView.hidden = YES;
        }
        if ([response[@"workLicenseImg"] integerValue] == 0 || response[@"workLicenseImg"] == NULL) {
            _workLicenseImgView.hidden = YES;
            _workLicenseImgContainerView.hidden = YES;
        }
        if ([response[@"driverImg"] integerValue] == 0 || response[@"driverImg"] == NULL) {
            _driverImgView.hidden = YES;
            _driverImgContainerView.hidden = YES;
        }
        if ([response[@"safeDutyInsureImg"] integerValue] == 0 || response[@"safeDutyInsureImg"] == NULL) {
            _safeDutyInsureImgView.hidden = YES;
            _safeDutyInsureImgContainerView.hidden = YES;
        }
        if ([response[@"stateImg"] integerValue] == 0 || response[@"stateImg"] == NULL) {
            _stateImgAsterisk.hidden = YES;
            _stateImgBgView.hidden = YES;
        }
        if ([response[@"driverLicenseImg"] integerValue] == 0 &&
            [response[@"identificationImg"] integerValue] == 0 &&
            [response[@"identificationBackImg"] integerValue] == 0 &&
            [response[@"workLicenseImg"] integerValue] == 0 &&
            [response[@"driverImg"] integerValue] == 0 &&
            [response[@"safeDutyInsureImg"] integerValue] == 0
//            && [response[@"stateImg"] integerValue] == 0
            ) {
            _photoBgView.hidden = YES;
        }
        
        
        if ([response[@"isLinked"] integerValue] == 0 || response[@"isLinked"] == NULL) {
            _affiliatAsterisk.hidden = YES;
            _affiliatedBgView.hidden = NO;
        }
        //输入框部分
        if ([response[@"name"] integerValue] == 0 || response[@"name"] == NULL) {
            _nameTFView.hidden = YES;
            _nameContainerView.hidden = YES;
        }
        if ([response[@"identificationNumber"] integerValue] == 0 || response[@"identificationNumber"] == NULL) {
            _idCardTFView.hidden = YES;
            _idCardContainerView.hidden = YES;
        }
        if ([response[@"workLicense"] integerValue] == 0 || response[@"workLicense"] == NULL) {
            _daoLuYunShuCongYeNumTFView.hidden = YES;
            _workLicenseContainerView.hidden = YES;
        }
        if ([response[@"homeAddress"] integerValue] == 0 || response[@"homeAddress"] == NULL) {
            _detailAddressTFView.hidden = YES;
            _homeAddressContainerView.hidden = YES;
        }
        if ([response[@"workCompany"] integerValue] == 0 || response[@"workCompany"] == NULL) {
            _workUnitTFView.hidden = YES;
            _workCompanyContainerView.hidden = YES;
        }
        if ([response[@"driverLicense"] integerValue] == 0 || response[@"driverLicense"] == NULL) {
            _vehicleJiaShiZhengTFView.hidden = YES;
            _driverLicenseContainerView.hidden = YES;
        }
        if ([response[@"realOwner"] integerValue] == 0 || response[@"realOwner"] == NULL) {
            _vehicleActualOwnerAsterisk.hidden = YES;
            _vehicleActualOwnerView.hidden = YES;
        }
        if ([response[@"realOwnerPhone"] integerValue] == 0 || response[@"realOwnerPhone"] == NULL) {
            _vehicleActualOwnerPhoneAsterisk.hidden = YES;//车辆实际所有人联系方式
            _vehicleActualOwnerPhoneView.hidden = YES;
        }
        if ([response[@"brand"] integerValue] == 0 || response[@"brand"] == NULL || _isTax == 0) {
            _vehicleBrandAsterisk.hidden = YES;//车辆品牌
            _vehicleBrandBgView.hidden = YES;
        }
        
        if ([response[@"areaList"] integerValue] == 0 || response[@"areaList"] == NULL) {
            _tongXunDiZhiTFView.hidden = YES;//通讯地址
            _areaListContainerView.hidden = YES;
        }
        if ([response[@"idCardDueDate"] integerValue] == 0 || response[@"idCardDueDate"] == NULL) {
            _idCardDueDateView.hidden = YES;//身份证到期日期
            _idCardDueDateContainerView.hidden = YES;
        }
        if ([response[@"phone"] integerValue] == 0 || response[@"phone"] == NULL) {
            _lianXiFangShiAsterisk.hidden = YES;
            _phoneContainerView.hidden = YES;
        }
        if ([response[@"workLicenseDueDate"] integerValue] == 0 || response[@"workLicenseDueDate"] == NULL) {
            _workLicenseDueDateTFView.hidden = YES;//道路运输从业资格证到期日期
            _workLicenseDueDateContainerView.hidden = YES;
        }
        if ([response[@"sex"] integerValue] == 0 || response[@"sex"] == NULL) {
            _sexBgView.hidden = YES;
        }
        
        if ( _addType == 1){
            _carBgView.hidden = YES;
        }
        
        //小于4.5吨区域
        if ([response[@"driverIssuingOrganizations"] integerValue] == 0 || response[@"driverIssuingOrganizations"] == NULL) {
            _jiaShiZhengFaZhengJiGuanTFView.hidden = YES;//驾驶证发证机关
            _driverIssuingOrganizationsContainerView.hidden = YES;
        }
        if ([response[@"vehicleClass"] integerValue] == 0 || response[@"vehicleClass"] == NULL) {
            _zhunJiavehicleTypeTFView.hidden = YES;//准驾车型
            _vehicleClassContainerView.hidden = YES;
        }
        if ([response[@"driverLicenseFromDate"] integerValue] == 0 || response[@"driverLicenseFromDate"] == NULL) {
            _driverLicenseFromDateTFView.hidden = YES;//驾驶证有效期开始
            _driverLicenseFromDateContainerView.hidden = YES;
        }
        if ([response[@"driverLicenseDueDate"] integerValue] == 0 || response[@"driverLicenseDueDate"] == NULL) {
            _driverLicenseDueDateTFView.hidden = YES;//驾驶证到期日期
            _driverLicenseDueDateContainerView.hidden = YES;
        }
        if ([response[@"workLicenseDueDate"] integerValue] == 0 || response[@"workLicenseDueDate"] == NULL) {
            _workLicenseDueDateContainerView.hidden = YES;
        }
        if ([response[@"driverIssuingOrganizations"] integerValue] == 0 &&
            [response[@"vehicleClass"] integerValue] == 0 &&
            [response[@"workLicenseDueDate"] integerValue] == 0 &&
            [response[@"driverLicenseFromDate"] integerValue] == 0 &&
            [response[@"driverLicenseDueDate"] integerValue] == 0
            ) {
            _noRequiredBgView.hidden = YES;
        }
        if ([response[@"password"] integerValue] == 0 || response[@"password"] == NULL) {
            _passwordOneView.hidden = YES;
            _passwordTwoView.hidden = YES;
        }
  
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}
- (void)getDriverInfoRequest {
    
    //需要变成基础服务的接口
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@/%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER, _driverCode) withParameter:@{ @"token":[UserDefaultUtil valueForKey:USER_TOKEN],} withVC:self netName:@"获取司机详情" success:^(id response, NSString *msg) {
                
        //性别
        _sex = [NSString nullToString:CJStringWithFormat(@"%@", response[@"sex"])];
        if ([_sex isEqual:@"1"]) {
            _manImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        } else if ([_sex isEqual:@"2"]){
            _womenImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        }
        _diverTypeStr = [NSString nullToString:CJStringWithFormat(@"%@", response[@"driverType"])];
        if ([_diverTypeStr isEqual:@"0"]) {
            _duliCarImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        } else if ([_diverTypeStr isEqual:@"2"]){
            _cheduiCarImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        }

        //身份证是否到期
        if (response[@"idCardDueDate"] != NULL) {
            
            NSInteger delta = [DCSpeedy calculateTimeDifference:response[@"idCardDueDate"]];

            if (delta<=30) {
                _idCardDueDateTF.textColor = UIColor.redColor;
                _idCardDueDateRemindLabel.hidden = NO;
            } else {
                _idCardDueDateTF.textColor = Dark_TextColor;
                _idCardDueDateRemindLabel.hidden = YES;
            }
        }
        
        //身份证有效期是否长期
        if ([response[@"idCardDueDate"] isEqual:@"9999-12-31"]) {
            _idCardIsLongtime = YES;
            _idCardDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        } else {
            _idCardIsLongtime = NO;
            _idCardDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
        }
        //司机驾驶证是否长期
        if ([response[@"driverLicenseDueDate"] isEqual:@"9999-12-31"]) {
            _licenseIsLongtime = YES;
            _driverLicenseDueDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        } else {
            _licenseIsLongtime = NO;
            _driverLicenseDueDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
        }
        
        //表单数组
        _nameTF.text = CJStringWithFormat(@"%@",response[@"name"]);
        _idCardTF.text = CJStringWithFormat(@"%@",response[@"identificationNumber"]);
        _lianXiFangShiTF.text = CJStringWithFormat(@"%@",response[@"phone"]);
        _daoLuYunShuCongYeNumTF.text = CJStringWithFormat(@"%@",response[@"workLicense"]);
        _passwordTF.text = @"";
        _passwordConfTF.text = @"";
        _detailAddressTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"homeAddress"])];//详细地址
        _workUnitTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"workCompany"])];//工作单位
        _vehicleJiaShiZhengTF.text = CJStringWithFormat(@"%@",response[@"driverLicense"]);
        _jiaShiZhengFaZhengJiGuanTF.text = response[@"issuingOrganizations"] == NULL ? @"" : response[@"issuingOrganizations"];
        _idCardDueDateTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"idCardDueDate"])];//身份证有效期
        _lastIdardDueDate = [NSString nullToString:CJStringWithFormat(@"%@", response[@"idCardDueDate"])];
        _vehicleActualOwnerTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"realOwner"])];//车辆实际所有人
        _vehicleActualOwnerPhoneTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"realOwnerPhone"])];//车辆实际所有人联系方式
        _vehicleBrandTF.text = [NSString nullToString:CJStringWithFormat(@"%@", response[@"vehicleVO"][@"brand"])];//车辆品牌
        
        NSInteger isGuaKao = [response[@"isLinked"] integerValue];//司机是否挂靠
        if (isGuaKao == 1) {
            _affiliatedImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
            _depenDealImgView.hidden = NO;
            _isLinked = YES;
        } else {
            _affiliatedImageView.image = image(@"gcy_img_home_business_nomal");
            _depenDealImgView.hidden = YES;
            _isLinked = NO;
        }
        
        _tongXunDiZhiTF.text = [NSString nullToString:CJStringWithFormat(@"%@%@%@", response[@"provinceName"],response[@"cityName"],response[@"countyName"])];//通信地址
        _zhunJiavehicleTypeTF.text = [NSString nullToString:CJStringWithFormat(@"%@",response[@"vehicleClass"])];//准驾车型
        _workLicenseDueDateTF.text = [NSString nullToString:CJStringWithFormat(@"%@",response[@"workLicenseDueDate"])];
        _driverLicenseFromDateTF.text = [NSString nullToString:CJStringWithFormat(@"%@",response[@"driverLicenseFromDate"])];
        _driverLicenseDueDateTF.text = [NSString nullToString:CJStringWithFormat(@"%@",response[@"driverLicenseDueDate"])];

        
        _provinceCode = [NSString nullToString:CJStringWithFormat(@"%@", response[@"provinceCode"])];//省
        _cityCode = [NSString nullToString:CJStringWithFormat(@"%@", response[@"cityCode"])];//市
        _countyCode = [NSString nullToString:CJStringWithFormat(@"%@", response[@"countyCode"])];//区
        _vehicleClass = [NSString nullToString:CJStringWithFormat(@"%@",response[@"vehicleClass"])];
        _workLicenseDueDate = [NSString nullToString:CJStringWithFormat(@"%@",response[@"workLicenseDueDate"])];
        _driverLicenseFromDate = [NSString nullToString:CJStringWithFormat(@"%@",response[@"driverLicenseFromDate"])];//司机驾驶证到期日期
        _driverLicenseDueDate = [NSString nullToString:CJStringWithFormat(@"%@",response[@"driverLicenseDueDate"])];
        _lastDriverLicenseDueDate = [NSString nullToString:CJStringWithFormat(@"%@",response[@"driverLicenseDueDate"])];
        //照片
        _jiaShiZhengUrl = CJStringWithFormat(@"%@",response[@"driverLicenseImg"]);
        _workLicenseImg = CJStringWithFormat(@"%@",response[@"workLicenseImg"]);
        _idCardFrontUrl = CJStringWithFormat(@"%@",response[@"identificationImg"]);
        _idCardReverseUrl = CJStringWithFormat(@"%@",response[@"identificationBackImg"]);
        _driverImg = CJStringWithFormat(@"%@",response[@"driverImg"]);
        _safeDutyInsureImg = [NSString nullToString:CJStringWithFormat(@"%@",response[@"safeDutyInsureImg"])];
        _stateImg = [NSString nullToString: response[@"stateImg"]];//车主声明照
        
        
        if ([DCSpeedy isBlankString:_jiaShiZhengUrl] == NO) {
            [_driverLicenseBtn setTitle:@"机动车驾驶证照片已上传" forState:UIControlStateNormal];
            [_driverLicenseBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        }
        if ([DCSpeedy isBlankString:_workLicenseImg] == NO) {
            [_workLicenseBtn setTitle:@"道路运输从业资格证照片已上传" forState:UIControlStateNormal];
            [_workLicenseBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        }
        if ([DCSpeedy isBlankString:_idCardFrontUrl] == NO) {
            [_identificationBtn setTitle:@"司机身份证人像面照片已上传" forState:UIControlStateNormal];
            [_identificationBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        }
        if ([DCSpeedy isBlankString:_idCardReverseUrl] == NO) {
            [_identificationBackBtn setTitle:@"司机身份证国徽面照片已上传" forState:UIControlStateNormal];
            [_identificationBackBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        }
        if ([DCSpeedy isBlankString:_driverImg] == NO) {
            [_driverImgBtn setTitle:@"司机半身照已上传" forState:UIControlStateNormal];
            [_driverImgBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        }
        if ([DCSpeedy isBlankString:_safeDutyInsureImg] == NO) {
            [_safeDutyInsureImgBtn setTitle:@"安全责任险照片已上传" forState:UIControlStateNormal];
            [_safeDutyInsureImgBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        }
        if ([DCSpeedy isBlankString:_stateImg] == NO) {
            [_stateImgBtn setTitle:@"车主声明照片已上传" forState:UIControlStateNormal];
            [_stateImgBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        }

#pragma mark - 证件是否过期判断(司机认证涉及2种证件)
        if ([DCSpeedy isBlankArr:response[@"overDueType"]] == NO) {
            NSArray *overDueArr = response[@"overDueType"];
            [overDueArr enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                if ([obj containsString:@"work"]) {
                    //从业资格证
                    [_workLicenseBtn setTitleColor:Red_Color forState:UIControlStateNormal];
                    _workLicenseDueDateTF.textColor = Red_Color;
                    
                } else if ([obj containsString:@"driver"]) {
                    //司机驾驶证
                    [_driverLicenseBtn setTitleColor:Red_Color forState:UIControlStateNormal];
                    _vehicleJiaShiZhengTF.textColor = Red_Color;
                }
            }];
        }

    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

- (void)btnSaveEvent {
    WEAKSELF
    
    if ([_dynamicFieldDic[@"password"] integerValue] == 1 && _dynamicFieldDic[@"password"] != NULL) {
        if ([DCSpeedy isBlankString:_passwordTF.text] || [DCSpeedy isBlankString:_passwordConfTF.text]) {
            [XSInfoView showInfo:@"请输入密码" onView:self.view];
            return;
        }
        
        if (_passwordTF.text != _passwordConfTF.text) {
            [XSInfoView showInfo:@"两次输入的密码不一致" onView:self.view];
            return;
        }
    }
    
     //图片校验
    if ([_dynamicFieldDic[@"driverLicenseImg"] integerValue] == 1 && _dynamicFieldDic[@"driverLicenseImg"] != NULL) {
        if ([DCSpeedy isBlankString:_jiaShiZhengUrl]) {
            [XSInfoView showInfo:@"请上传机动车驾驶证照片" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"identificationImg"] integerValue] == 1 && _dynamicFieldDic[@"identificationImg"] != NULL) {
        if ([DCSpeedy isBlankString:_idCardFrontUrl]) {
            [XSInfoView showInfo:@"请上传司机身份证人像面照片" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"identificationBackImg"] integerValue] == 1 && _dynamicFieldDic[@"identificationBackImg"] != NULL) {
        if ([DCSpeedy isBlankString:_idCardReverseUrl]) {
            [XSInfoView showInfo:@"请上传司机身份证国徽面照片" onView:self.view];
            return;
        }
    }
    
    if ([_dynamicFieldDic[@"workLicenseImg"] integerValue] == 1 && _dynamicFieldDic[@"workLicenseImg"] != NULL) {
        if ([DCSpeedy isBlankString:_workLicenseImg]) {
            [XSInfoView showInfo:@"请上传道路运输从业资格证照片" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"driverImg"] integerValue] == 1 && _dynamicFieldDic[@"driverImg"] != NULL) {
        if ([DCSpeedy isBlankString:_driverImg]) {
            [XSInfoView showInfo:@"请上传司机半身照" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"safeDutyInsureImg"] integerValue] == 1 && _dynamicFieldDic[@"safeDutyInsureImg"] != NULL) {
        if ([DCSpeedy isBlankString:_safeDutyInsureImg]) {
            [XSInfoView showInfo:@"请上传安全责任险照片" onView:self.view];
            return;
        }
    }
//    if ([_dynamicFieldDic[@"stateImg"] integerValue] == 1 && _dynamicFieldDic[@"stateImg"] != NULL && _isTax == 1) {
//        if ([DCSpeedy isBlankString:_stateImg]) {
//            [XSInfoView showInfo:@"请上传车主声明照" onView:self.view];
//            return;
//        }
//    }
    
    ///表单校验
    if ([_dynamicFieldDic[@"name"] integerValue] == 1 && _dynamicFieldDic[@"name"] != NULL) {
        if ([DCSpeedy isBlankString:_nameTF.text]) {
            [XSInfoView showInfo:@"请填写驾驶员姓名" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"identificationNumber"] integerValue] == 1 && _dynamicFieldDic[@"identificationNumber"] != NULL) {
        if ([DCSpeedy isBlankString:_idCardTF.text]) {
            [XSInfoView showInfo:@"请填写身份证号" onView:self.view];
            return;
        }
//        if (_idCardTF.text.length != 18) {
//            [XSInfoView showInfo:@"身份证号必须为18位" onView:self.view];
//            return;
//        }
        if ([CYCheckRegular cy_checkUserIcyard:_idCardTF.text] == NO) {
            [XSInfoView showInfo:@"请填写正确的身份证号" onView:self.view];
            return;
        }
    }
    
    if ([DCSpeedy isBlankString:_lianXiFangShiTF.text]) {
        [XSInfoView showInfo:@"请填写联系方式" onView:self.view];
        return;
    }
//    if ([_dynamicFieldDic[@"phone"] integerValue] == 1 && _dynamicFieldDic[@"phone"] != NULL) {
//        if ([DCSpeedy isBlankString:_lianXiFangShiTF.text]) {
//            [XSInfoView showInfo:@"请填写联系方式" onView:self.view];
//            return;
//        }
//    }
    
    if ([_dynamicFieldDic[@"workLicense"] integerValue] == 1 && _dynamicFieldDic[@"workLicense"] != NULL) {
        if ([DCSpeedy isBlankString:_daoLuYunShuCongYeNumTF.text]) {
            [XSInfoView showInfo:@"请填写道路运输从业资格证号" onView:self.view];
            return;
        }
//        if (_daoLuYunShuCongYeNumTF.text.length != 18) {
//
//        } else {
//            [XSInfoView showInfo:@"道路运输从业资格证号必须为18位" onView:self.view];
//            return;
//        }
    }
    if ([_dynamicFieldDic[@"homeAddress"] integerValue] == 1 && _dynamicFieldDic[@"homeAddress"] != NULL) {
        if ([DCSpeedy isBlankString:_detailAddressTF.text]) {
            [XSInfoView showInfo:@"请填写详细地址" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"workCompany"] integerValue] == 1 && _dynamicFieldDic[@"workCompany"] != NULL) {
        if ([DCSpeedy isBlankString:_workUnitTF.text]) {
            [XSInfoView showInfo:@"请填写工作单位" onView:self.view];
            return;
        }
    }
  
    if ([_dynamicFieldDic[@"driverLicense"] integerValue] == 1 && _dynamicFieldDic[@"driverLicense"] != NULL) {
        if ([DCSpeedy isBlankString:_vehicleJiaShiZhengTF.text]) {
            [XSInfoView showInfo:@"请填写机动车驾驶证号" onView:self.view];
            return;
        }
//        if (_vehicleJiaShiZhengTF.text.length == 15 || _vehicleJiaShiZhengTF.text.length == 18) {
//
//        } else {
//            [XSInfoView showInfo:@"机动车驾驶证号必须为15位或18位" onView:self.view];
//            return;
//        }
        
    }
    
//    if ([_dynamicFieldDic[@"realOwner"] integerValue] == 1 && _dynamicFieldDic[@"realOwner"] != NULL && _isTax == 1) {
//        if ([DCSpeedy isBlankString:_vehicleActualOwnerTF.text]) {
//            [XSInfoView showInfo:@"请填写车辆实际所有人" onView:self.view];
//            return;
//        }
//    }
//
//    if ([_dynamicFieldDic[@"realOwnerPhone"] integerValue] == 1 && _dynamicFieldDic[@"realOwnerPhone"] != NULL && _isTax == 1) {
//        if ([DCSpeedy isBlankString:_vehicleActualOwnerPhoneTF.text]) {
//            [XSInfoView showInfo:@"请填写车辆实际所有人联系方式" onView:self.view];
//            return;
//        }
//    }
//
//    if ([_dynamicFieldDic[@"brand"] integerValue] == 1 && _dynamicFieldDic[@"brand"] != NULL && _isTax == 1) {
//        if ([DCSpeedy isBlankString:_vehicleBrandTF.text]) {
//            [XSInfoView showInfo:@"请填写车辆品牌" onView:self.view];
//            return;
//        }
//    }
    
    //如果是江苏省
    if (_reportPlatform == 3) {
        if ([_dynamicFieldDic[@"sex"] integerValue] == 1 && _dynamicFieldDic[@"sex"] != NULL) {
            if ([DCSpeedy isBlankString:_sex]) {
                [XSInfoView showInfo:@"请选择性别" onView:self.view];
                return;
            }
        }
    }
    if ([_dynamicFieldDic[@"driverType"] integerValue] == 1 && _dynamicFieldDic[@"driverType"] != NULL && _addType != 1) {
        //司机类型
        if ([DCSpeedy isBlankString:_cityCode]) {
            [XSInfoView showInfo:@"请选择注册司机类型" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"areaList"] integerValue] == 1 && _dynamicFieldDic[@"areaList"] != NULL) {
        //通讯地址
        if ([DCSpeedy isBlankString:_cityCode]) {
            [XSInfoView showInfo:@"请选择通信地址" onView:self.view];
            return;
        }
    }
    
    if ([_dynamicFieldDic[@"idCardDueDate"] integerValue] == 1 && _dynamicFieldDic[@"idCardDueDate"] != NULL) {
        if ([DCSpeedy isBlankString:_idCardDueDateTF.text]) {
            [XSInfoView showInfo:@"请选择身份证到期日期" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"driverLicenseFromDate"] integerValue] == 1 && _dynamicFieldDic[@"driverLicenseFromDate"] != NULL) {
        if ([DCSpeedy isBlankString:_driverLicenseFromDateTF.text]) {
            [XSInfoView showInfo:@"请选择驾驶证开始日期" onView:self.view];
            return;
        }
    }
    if ([_dynamicFieldDic[@"driverLicenseDueDate"] integerValue] == 1 && _dynamicFieldDic[@"driverLicenseDueDate"] != NULL) {
        if ([DCSpeedy isBlankString:_driverLicenseDueDateTF.text]) {
            [XSInfoView showInfo:@"请选择驾驶证到期日期" onView:self.view];
            return;
        }
    }
   
    if ([_dynamicFieldDic[@"driverIssuingOrganizations"] integerValue] == 1 && _dynamicFieldDic[@"driverIssuingOrganizations"] != NULL) {
        if ([DCSpeedy isBlankString:_jiaShiZhengFaZhengJiGuanTF.text]) {
            [XSInfoView showInfo:@"请填写驾驶证发证机关" onView:self.view];
            return;
        }
    }

    if ([_dynamicFieldDic[@"vehicleClass"] integerValue] == 1 && _dynamicFieldDic[@"vehicleClass"] != NULL) {
        if ([DCSpeedy isBlankString:_zhunJiavehicleTypeTF.text]) {
            [XSInfoView showInfo:@"请选择准驾类型" onView:self.view];
            return;
        }
    }
    
    if ([_dynamicFieldDic[@"workLicenseDueDate"] integerValue] == 1 && _dynamicFieldDic[@"workLicenseDueDate"] != NULL) {
        if ([DCSpeedy isBlankString:_workLicenseDueDateTF.text]) {
            [XSInfoView showInfo:@"请选择道路运输从业资格证到期日期" onView:self.view];
            return;
        }
    }
    
    NSDictionary *parmas = @{
        @"name": _nameTF.text,
        @"identificationNumber": _idCardTF.text,
        @"phone": _lianXiFangShiTF.text,
        @"workLicense": _daoLuYunShuCongYeNumTF.text,
        @"password": _passwordTF.text,
        @"homeAddress": _detailAddressTF.text,//详细地址
        @"workCompany": _workUnitTF.text,//工作单位
        @"driverLicense": _vehicleJiaShiZhengTF.text,
        @"issuingOrganizations": _jiaShiZhengFaZhengJiGuanTF.text,//驾驶证发证机关
        @"vehicleClass": _vehicleClass,//准驾车型
        @"workLicenseDueDate": _workLicenseDueDateTF.text,//从业资格证到期日期
        @"driverLicenseFromDate": _driverLicenseFromDateTF.text,//驾驶证有效期开始
        @"driverLicenseDueDate": _driverLicenseDueDateTF.text,//司机驾驶证到期日期
        @"driverLicenseImg": _jiaShiZhengUrl,//司机驾驶证图片
        @"workLicenseImg": _workLicenseImg,//从业资格证照片
        @"identificationImg": _idCardFrontUrl,//身份证正面
        @"identificationBackImg": _idCardReverseUrl,//身份证反面
        @"driverImg": _driverImg,//司机照片
        @"safeDutyInsureImg": _safeDutyInsureImg,//安全责任险照片
        @"sex": _sex,//性别
        @"driverType": _diverTypeStr,//类型
        
        //            @"vehicleLicenseImg": _vehicleLicenseImg,//行驶证
        @"provinceCode": _provinceCode,
        @"cityCode": _cityCode,
        @"countyCode": _countyCode,
        
        @"idCardDueDate": _idCardDueDateTF.text,//身份证有效期
        
        @"partyCode": [DCSpeedy isBlankString:_partyCode] ? @"" : _partyCode,
        @"code": [DCSpeedy isBlankString:_driverCode] ? @"" : _driverCode,
        @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
    };
    
    [HTTPManager postNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DRIVER_ADDORUPDATE) withParameter:parmas withVC:self netName:@"新增/修改司机" success:^(id response, NSString *msg) {
        
        [XSInfoView showInfo:msg onView:weakSelf.view];
        [KNotificationCenter postNotificationName:DUE_ALERT object:nil];

        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void){
            [weakSelf.navigationController popViewControllerAnimated:YES];
        });
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];

}

#pragma mark - DeliveredImageUrlDelegate
- (void)getImageUrlSting:(NSString *)string andImageType:(NSInteger)type {
    /**
     0 驾驶证
     1 从业资格证
     2 身份证正面
     3 身份证反面
     4 司机照
     */
    
    NSString *ocrType = @"";
    
    if (type == 0) {
        //驾驶证
        ocrType = @"ocrDrivingLicense";
        _jiaShiZhengUrl = string;
        [_driverLicenseBtn setTitle:@"机动车驾驶证照片已上传" forState:UIControlStateNormal];
        [_driverLicenseBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        
    } else if (type == 1) {
        //从业资格证
        ocrType = @"ocrQualificationCertificate";
        _workLicenseImg = string;
        [_workLicenseBtn setTitle:@"道路运输从业资格证照片已上传" forState:UIControlStateNormal];
        [_workLicenseBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        
    } else if (type == 2) {
        //身份证
        ocrType = @"ocrIdidentityCardFront";
        _idCardFrontUrl = string;
        [_identificationBtn setTitle:@"司机身份证人像面照片已上传" forState:UIControlStateNormal];
        [_identificationBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        
    } else if (type == 3) {
        ocrType = @"ocrIdidentityCardFrontBack";
        _idCardReverseUrl = string;
        [_identificationBackBtn setTitle:@"司机身份证国徽面照片已上传" forState:UIControlStateNormal];
        [_identificationBackBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        
    } else if (type == 4) {
        
        _driverImg = string;
        [_driverImgBtn setTitle:@"司机半身照已上传" forState:UIControlStateNormal];
        [_driverImgBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        
    } else if (type == 15) {
        
        _safeDutyInsureImg = string;
        [_safeDutyInsureImgBtn setTitle:@"安全责任险照片已上传" forState:UIControlStateNormal];
        [_safeDutyInsureImgBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
        
    } else if (type == 17) {
        _stateImg = string;
        [_stateImgBtn setTitle:@"车主声明照片已上传" forState:UIControlStateNormal];
        [_stateImgBtn setTitleColor:Dark_TextColor forState:UIControlStateNormal];
    }
    
#pragma mark - OCR识别
    if (type == 2 || type == 3 || type == 1 || type == 0) {
        
        NSDictionary *parmas = @{
            @"image": string,
            @"ocrType": ocrType,
            @"token":[UserDefaultUtil valueForKey:USER_TOKEN],
        };
        
        [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-tps-api",[ReAddressDynamic shared].baseUrl], NTOCC_OCRCARD) withParameter:parmas withVC:self netName:@"OCR识别" success:^(id response, NSString *msg) {
            
            [XSInfoView showInfo:msg onView:self.view];
            
            if (type == 2) {
                //身份证
                
                if ([DCSpeedy isBlankString:response[@"name"]] == NO) {
                    _nameTF.text = response[@"name"];
                }
                if ([DCSpeedy isBlankString:response[@"identity"]] == NO) {
                    _idCardTF.text = response[@"identity"];
                }
                if ([DCSpeedy isBlankString:response[@"provinceCode"]] == NO) {
                    _provinceCode = response[@"provinceCode"];
                }
                if ([DCSpeedy isBlankString:response[@"cityCode"]] == NO) {
                    _cityCode = response[@"cityCode"];
                }
                if ([DCSpeedy isBlankString:response[@"countyCode"]] == NO) {
                    _countyCode = response[@"countyCode"];
                }
                if ([DCSpeedy isBlankString:response[@"provinceName"]] == NO && [DCSpeedy isBlankString:response[@"cityName"]] == NO && [DCSpeedy isBlankString:response[@"countyName"]] == NO) {
                    NSString *address = CJStringWithFormat(@"%@%@%@",response[@"provinceName"],response[@"cityName"],response[@"countyName"]);
                    _tongXunDiZhiTF.text = address;
                }
            } else if (type == 3) {
                //身份证反面
                if ([DCSpeedy isBlankString:response[@"expiryDate"]] == NO && ([response[@"expiryDate"] isEqual:@"长期"] || [response[@"expiryDate"] isEqual:@"9999-12-31"])) {
                    _idCardIsLongtime = YES;
                    _idCardDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
                    _idCardDueDateTF.text = @"9999-12-31";
                } else {
                    _idCardIsLongtime = NO;
                    _idCardDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
                    _idCardDueDateTF.text = [DCSpeedy ocrDateFormatter:response[@"expiryDate"]];
                }
                
            } else if (type == 1) {
                //从业资格证
                if ([DCSpeedy isBlankString:response[@"zhenghao"]] == NO) {
                    _daoLuYunShuCongYeNumTF.text = response[@"zhenghao"];
                }
                if ([DCSpeedy isBlankString:response[@"youxiaoqixian"]] == NO) {
                    _workLicenseDueDateTF.text = [NSString nullToString:[DCSpeedy ocrDateFormatter:response[@"youxiaoqixian"]]];
                    _workLicenseDueDate = [NSString nullToString:[DCSpeedy ocrDateFormatter:response[@"youxiaoqixian"]]];
                }
                
            } else if (type == 0) {
                //驾驶证
                if ([DCSpeedy isBlankString:response[@"certificateNumber"]] == NO) {
                    _vehicleJiaShiZhengTF.text = response[@"certificateNumber"];
                }
                
                //准驾车型
                if ([DCSpeedy isBlankString:response[@"vehicleClass"]] == NO && [DCSpeedy isBlankString:response[@"vehicleClassName"]] == NO) {
                    _vehicleClass = response[@"vehicleClass"];
                    _zhunJiavehicleTypeTF.text = response[@"vehicleClassName"];
                }
                
                //驾驶证发证机关
                //                    jszfzjgTextField.text = response[@"certificateNumber"];
                
                //驾驶证有效期自
                if ([DCSpeedy isBlankString:response[@"validStartDate"]] == NO) {
                    _driverLicenseFromDate = [DCSpeedy ocrDateFormatter:response[@"validStartDate"]];
                    _driverLicenseFromDateTF.text = _driverLicenseFromDate;
                }
                
                //驾驶证有效期至
                if ([DCSpeedy isBlankString:response[@"validDate"]] == NO && ([response[@"validDate"] isEqual:@"长期"] || [response[@"validDate"] isEqual:@"9999-12-31"])) {
                    _licenseIsLongtime = YES;
                    _driverLicenseDueDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
                    _driverLicenseDueDateTF.text = @"9999-12-31";
                } else {
                    _licenseIsLongtime = NO;
                    _driverLicenseDueDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
                    _driverLicenseDueDateTF.text = [DCSpeedy ocrDateFormatter:response[@"validDate"]];
                }
            }
            
        } failure:^(NSInteger code, NSString *msg) {
            
        }];
        
    }
        
}

#pragma mark - CYChooseRegionDelegate
- (void)getAllInfoProvinceCode:(NSString *)provinceCode provinceName:(NSString *)provinceName cityCode:(NSString *)cityCode cityName:(NSString *)cityName countyCode:(NSString *)countyCode countyName:(NSString *)countyName {
    
    if ([DCSpeedy isBlankString:countyCode] == YES) {
        [XSInfoView showInfo:@"通讯地址请精确到区/县" onView:self.view];
        
        [[CYCityChooseView shared] show];
        [CYCityChooseView shared].pageShowFlag = 1;
        [CYCityChooseView shared].delegate = self;
        
        return;
    }
    
    NSString *address = CJStringWithFormat(@"%@%@%@",provinceName,cityName,countyName);
    
    _tongXunDiZhiTF.text = address;
    
    _provinceCode = provinceCode;
    _cityCode = cityCode;
    _countyCode = countyCode;
}

#pragma mark -- STPickerSingleDelegate
- (void)pickerSingle:(STPickerSingle *)pickerSingle selectedTitle:(NSString *)selectedTitle {
    //车辆类型
    _zhunJiavehicleTypeTF.text = selectedTitle;
    NSInteger index = [self.vehicleClassArray indexOfObject:selectedTitle];
    _vehicleClass = self.vechicleClassModelArray[index][@"code"];
}


- (void)driverLicenseBtnEvent {
    //驾驶证
    self.uploadImgVC.imageType = 0;
    self.uploadImgVC.imageNetUrl = _jiaShiZhengUrl;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)identificationBtnEvent {
    //身份证正面
    self.uploadImgVC.imageType = 2;
    self.uploadImgVC.imageNetUrl = _idCardFrontUrl;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)identificationBackBtnEvent {
    //身份证反面
    self.uploadImgVC.imageType = 3;
    self.uploadImgVC.imageNetUrl = _idCardReverseUrl;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)workLicenseBtnEvent {
    //道路运输从业资格证
    self.uploadImgVC.imageType = 1;
    self.uploadImgVC.imageNetUrl = _workLicenseImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)driverImgBtnEvent {
    //司机照
    self.uploadImgVC.imageType = 4;
    self.uploadImgVC.imageNetUrl = _driverImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)safeDutyInsureImgBtnEvent {
    //安全责任险照
    self.uploadImgVC.imageType = 15;
    self.uploadImgVC.imageNetUrl = _safeDutyInsureImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
- (void)stateImgBtnEvent {
    //车主声明照
    self.uploadImgVC.imageType = 17;
    self.uploadImgVC.imageNetUrl = _stateImg;
    [self.navigationController pushViewController:self.uploadImgVC animated:YES];
}
//是否挂靠
- (void)affiliatedBtnEvent {
    if (_isLinked) {
        _affiliatedImageView.image = image(@"gcy_img_home_business_nomal");
        _depenDealImgView.hidden = YES;
    } else {
        _affiliatedImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        _depenDealImgView.hidden = NO;
    }
    _isLinked = !_isLinked;
}

///准驾车型
- (void)zhunJiavehicleTypeChooseEvent {
    STPickerSingle *vehicleClassPickerSingle = [[STPickerSingle alloc]init];
    vehicleClassPickerSingle.widthPickerComponent = ScreenW;
    [vehicleClassPickerSingle setArrayData:self.vehicleClassArray];
    [vehicleClassPickerSingle setTitle:@"请选择准驾类型"];
    [vehicleClassPickerSingle setContentMode:STPickerContentModeBottom];
    [vehicleClassPickerSingle setDelegate:self];
    [vehicleClassPickerSingle show];
}
- (void)workLicenseDueDateEvent {
    //道路运输从业资格证到期日期
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMD];
    datePickerView.title = @"选择日期";
    datePickerView.isAutoSelect = NO;
    datePickerView.showToday = NO; // 是否显示“今天”
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        _workLicenseDueDateTF.text = selectValue;
    };
    [datePickerView show:self];
}
///驾驶证有效期自
- (void)driverLicenseFromDateEvent {
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMD];
    datePickerView.title = @"机动车驾驶证有效期自";
    datePickerView.isAutoSelect = NO;
    datePickerView.showToday = NO; // 是否显示“今天”
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        _driverLicenseFromDateTF.text = selectValue;
    };
    [datePickerView show:self];
}
///驾驶证有效期至
- (void)driverLicenseDueDateEvent {
    //驾驶证有效期至
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMD];
    datePickerView.title = @"驾驶证有效期至";
    datePickerView.isAutoSelect = NO;
    datePickerView.showToday = NO; // 是否显示“今天”
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        _driverLicenseDueDateTF.text = selectValue;
        _lastDriverLicenseDueDate = selectValue;
    };
    [datePickerView show:self];
}
///身份证到期日期
- (void)idCardDueDateEvent{
    BRDatePickerView *datePickerView = [[BRDatePickerView alloc]initWithPickerMode:BRDatePickerModeYMD];
    datePickerView.title = @"身份证到期日期";
    datePickerView.isAutoSelect = NO;
    datePickerView.showToday = NO; // 是否显示“今天”
    datePickerView.resultBlock = ^(NSDate *selectDate, NSString *selectValue) {
        _idCardDueDateTF.text = selectValue;
        _lastIdardDueDate = selectValue;
    };
    [datePickerView show:self];
}
- (void)sexManEvent {
    _manImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _womenImageView.image = image(@"gcy_img_home_business_nomal");
    _sex = @"1";
}
- (void)sexWomanEvent {
    _manImageView.image = image(@"gcy_img_home_business_nomal");
    _womenImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _sex = @"2";
}
- (void)duliCarEvent{
    _duliCarImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _cheduiCarImageView.image = image(@"gcy_img_home_business_nomal");
    _diverTypeStr = @"0";
}
- (void)cheduiCarEvent{
    _duliCarImageView.image = image(@"gcy_img_home_business_nomal");
    _cheduiCarImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
    _diverTypeStr = @"2";
}
- (void)idCardDateIsLongtimeEvent {
    if (_idCardIsLongtime) {
        //不是长期
        _idCardDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
//        _idCardDueDateTF.text = [DCSpeedy generalGetCurrentDate:@"YYYY-MM-dd"];
        _idCardDueDateTF.text = _lastIdardDueDate;
        
    } else {
        //长期
        _idCardDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        _idCardDueDateTF.text = @"9999-12-31";
    }
    _idCardIsLongtime = !_idCardIsLongtime;
}

- (void)driverLicenseDueDateIsLongtimeEvent {
    if (_licenseIsLongtime) {
        //长期
        _driverLicenseDueDateIsLongtimeImageView.image = image(@"gcy_img_home_business_nomal");
//        _driverLicenseDueDateTF.text = [DCSpeedy generalGetCurrentDate:@"YYYY-MM-dd"];
        _driverLicenseDueDateTF.text = _lastDriverLicenseDueDate;

    } else {
        //不是长期
        _driverLicenseDueDateIsLongtimeImageView.image = [image(@"gcy_img_home_business_select") imageChangeColor:Theme_ColorValue];
        _driverLicenseDueDateTF.text = @"9999-12-31";
    }
    _licenseIsLongtime = !_licenseIsLongtime;
}

///通讯地址
- (void)provincesCityCountyChooseEvent {
    //通讯地址
    [[CYCityChooseView shared] show];
    [CYCityChooseView shared].pageShowFlag = 1;
    [CYCityChooseView shared].delegate = self;
}

- (void)vehicleClassListRequest {
    WEAKSELF
    
    NSDictionary *parmas = @{@"types": @"vehicleTypeAllow", @"token":[UserDefaultUtil valueForKey:USER_TOKEN],};
    [HTTPManager getNetworkRequest:CJStringWithFormat(@"%@%@", [NSString stringWithFormat:@"%@/ntocc-basic-api",[ReAddressDynamic shared].baseUrl], DICT_LISTDICT) withParameter:parmas withVC:self netName:@"准驾类型列表" success:^(id response, NSString *msg) {
        
        if ([[response firstObject][@"dictList"] count] != 0) {
            self.vechicleClassModelArray = [response firstObject][@"dictList"];
            [[response firstObject][@"dictList"] enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                [weakSelf.vehicleClassArray addObject:obj[@"name"]];
            }];
            
        }
        
    } failure:^(NSInteger code, NSString *msg) {
        
    }];
}

- (NSMutableArray *)vehicleClassArray {
    if (!_vehicleClassArray) {
        _vehicleClassArray = [[NSMutableArray alloc] init];
    }
    return _vehicleClassArray;
}
- (NSMutableArray *)vechicleClassModelArray {
    if (!_vechicleClassModelArray) {
        _vechicleClassModelArray = [[NSMutableArray alloc] init];
    }
    return _vechicleClassModelArray;
}
- (ImageUploadViewController *)uploadImgVC {
    if (!_uploadImgVC) {
        _uploadImgVC = [[ImageUploadViewController alloc] init];
//        _uploadImgVC.isAddWatermark = YES;
        _uploadImgVC.delegate = self;
    }
    return _uploadImgVC;
}

#pragma mark - 表单验证规范
- (void)formValidationSetup {
    
    /*姓名*/
    _nameTF.textFieldType = CJTextFieldStringTypeNone;
    _nameTF.maxLength = 20;
    
    /*身份证号*/
    _idCardTF.textFieldType = CJTextFieldStringTypeNone;
    _idCardTF.keyboardType = UIKeyboardTypeNumbersAndPunctuation; 
    _idCardTF.maxLength = 18;
    
    /*联系电话*/
    _lianXiFangShiTF.textFieldType = CJTextFieldStringTypeNumber;
    _lianXiFangShiTF.keyboardType = UIKeyboardTypeNumberPad;
    _lianXiFangShiTF.maxLength = 11;
    
    /*道路运输从业资格证*/
    _daoLuYunShuCongYeNumTF.textFieldType = CJTextFieldStringTypePassword;
//    _daoLuYunShuCongYeNumTF.keyboardType = UIKeyboardTypeNumberPad;
    _daoLuYunShuCongYeNumTF.maxLength = 128;
    
    /*密码*/
//    _passwordTF.textFieldType = CJTextFieldStringTypePassword;
    _passwordTF.maxLength = 20;
    
    /*确认密码*/
//    _passwordConfTF.textFieldType = CJTextFieldStringTypePassword;
    _passwordConfTF.maxLength = 20;
    
    /*详细地址*/
    _detailAddressTF.textFieldType = CJTextFieldStringTypeNone;
    _detailAddressTF.maxLength = 128;
    
    /*工作单位*/
    _workUnitTF.textFieldType = CJTextFieldStringTypeNone;
    _workUnitTF.maxLength = 128;
    
    /*机动车驾驶证号*/
    _vehicleJiaShiZhengTF.textFieldType = CJTextFieldStringTypePassword;
    _vehicleJiaShiZhengTF.maxLength = 128;
    
    /*驾驶证发证机关*/
    _jiaShiZhengFaZhengJiGuanTF.textFieldType = CJTextFieldStringTypeNone;
    _jiaShiZhengFaZhengJiGuanTF.maxLength = 20;
    
    /*车辆实际所有人*/
    _vehicleActualOwnerTF.textFieldType = CJTextFieldStringTypeNone;
    _vehicleActualOwnerTF.maxLength = 10;
    
    /*车辆实际所有人联系方式*/
    _vehicleActualOwnerPhoneTF.textFieldType = CJTextFieldStringTypeNumber;
    _vehicleActualOwnerPhoneTF.keyboardType = UIKeyboardTypeNumberPad;
    _vehicleActualOwnerPhoneTF.maxLength = 11;
    
    /*车辆品牌*/
    _vehicleBrandTF.textFieldType = CJTextFieldStringTypeNone;
    _vehicleBrandTF.maxLength = 10;
}

@end
